package com.adingxiong.quickstart.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @ClassName FastdfsProperties
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/9/8 11:33
 **/
@Data
@ConfigurationProperties(prefix = "fdfs",ignoreInvalidFields = true)
@Slf4j
public class FastdfsProperties implements InitializingBean {


    private String reqHost;

    private String reqPort;

    private String webServerUrl;

    private String soTimeout;

    @Override
    public void afterPropertiesSet() throws Exception {
        log.debug("fdfs.reqHost is {},fdfs.reqPort is {},fdfs.webServerUrl is {}",getReqHost(),getReqPort(),getWebServerUrl());
        if (StringUtils.isBlank(getReqHost())) {
            throw new IllegalStateException("Property \"fdfs.reqHost\" cannot  be blank");
        }
        if (StringUtils.isBlank(getReqPort())) {
            throw new IllegalStateException("Property \"fdfs.reqPort\" cannot  be blank");
        }
        if (StringUtils.isBlank(getWebServerUrl())) {
            throw new IllegalStateException("Property \"fdfs.webServerUrl\" cannot  be blank");
        }
        if (StringUtils.isBlank(getSoTimeout())) {
            throw new IllegalStateException("Property \"fdfs.soTimeout\" cannot  be blank");
        }

    }
}
